import React, { Component } from "react";

import userHeadIcon from "../images/user-head-icon.png";

import config from '../config.js'

import "./UserHead.css";

class UserHead extends Component {
  state = {
    imgurl:config.url.IMAGE_URL_HOST,
    info:{}
  };

  initComponent(){
    var info=config.getInfo();
    this.setInfoToState(info)
  }

  setInfoToState(info){
    this.setState({
        info:info
    })
  }
  
  componentWillMount(){
    this.initComponent()
  }

  render() {
    return (
      <div className="user-head">
        <img src={ this.getUserHeadIcon() } alt="头像" className="user-head-icon" />
        <p className="user-head-nickname">{this.state.info.name}</p>
      </div>
    );
  }

  

  getUserHeadIcon(){
    return this.state.info.icon == "" || this.state.info.icon == null ? userHeadIcon : this.state.imgurl + this.state.info.icon;
  }
}

export default UserHead;
